package com.tcm.doctor.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.pager.PageBean;
import com.base.core.utils.R;

import com.tcm.order.domain.dto.OrderDTO;
import com.tcm.order.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor")
@RestController
public class OrderController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private OrderService orderService;


    /**
     * 查询订单列表
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获得用户所有订单")
    @GetMapping("/order/list/page")
    public R listPageByDoctorId(@RequestParam Long doctorId,
                              @RequestParam(defaultValue = "1") Long page,
                              @RequestParam(defaultValue = "10") Long pagesize) {
        PageBean<OrderDTO> orderPageBean;
        try {
            orderPageBean = orderService.listPageOrderByDoctor(doctorId, page, pagesize);
        }catch (ServiceException e) {
            e.printStackTrace();
            return R.fail(e.getResult().getCode(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
        return R.success(orderPageBean);
    }

    /**
     * 医生获得订单详情
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/order/detail")
    public R findOrderDetail(@RequestParam Long orderId) throws Exception {
        OrderDTO orderVo = orderService.findDetailByOrderId(orderId);
        return R.success(orderVo);
    }


}
